package org.wisdom.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.wisdom.request.PutPersonalDetailsRequest;
import org.wisdom.response.PersonalDetailsResponse;
import org.wisdom.response.Result;
import org.wisdom.service.UserProfileService;

import java.io.IOException;

@RestController
@RequestMapping("/user/profile")
public class UserProfileController {

    @Autowired
    UserProfileService userProfileService;

    @GetMapping("/avatar")
    public Result<String> getAvatar() {
        return Result.success(userProfileService.getAvatar());
    }

    @PostMapping("/avatar")
    public Result<?> postAvatar(MultipartFile file) throws IOException {
        userProfileService.postAvatar(file);
        return Result.successWithMsg("文件上传成功");
    }

    @PutMapping("/personal-details")
    public Result<?> putPersonalDetails(@RequestBody PutPersonalDetailsRequest putPersonalDetailsRequest) {
        userProfileService.putPersonalDetails(putPersonalDetailsRequest);
        return Result.successWithMsg("修改成功");
    }

    @GetMapping("/personal-details")
    public Result<PersonalDetailsResponse> getPersonalDetails() {
        return Result.success(userProfileService.getPersonalDetails());
    }
}
